<?php
/**
 * Theme's Functions and Definitions
 *
 *
 * @file           functions.php
 * @package        WordPress
 * @subpackage     Shell
 * @author          Emil Uzelac, nofearinc
 * @copyright      2003 - 2012 ThemeID, 2013 DevWP
 * @license        license.txt
 * @version        Release: 1.1
 * @filesource     wp-content/themes/shell-lite/includes/functions.php
 * @link           http://codex.wordpress.org/Theme_Development#Functions_File
 * @since          available since Release 1.0
 */
?>
<?php
/**
 * Fire up the engines boys and girls let's start theme setup.
 */
add_action('after_setup_theme', 'shell_setup');
//if (!function_exists('shell_setup')):

function shell_setup() {
	register_nav_menu('header_menu', __('导航菜单', 'shell'));
	register_nav_menu('footer_menu', __('底部菜单', 'shell'));

}
//endif;

//浓缩图开始
function getFirstImage($postId,$w=100,$h=65) {
	$args = array(
		'numberposts' => 1,
		'order'=> 'ASC',
		'post_mime_type' => 'image',
		'post_parent' => $postId,
		'post_status' => null,
		'post_type' => 'attachment'
		);
		$attachments = get_children($args);
		
		// 如果没有上传图片, 返回空字符串
		if(!$attachments) {
			return '';
		}

		// 获取缩略图中的第一个图片, 并组装成 HTML 节点返回
		$image = array_pop($attachments);
		
		$imageSrc = wp_get_attachment_image_src($image->ID, 'big');
		//print_r($image->ID);
		$pattern = '/wp-content\/uploads\/([\d]{4}\/[\d]{2}\/.+?)(\.png|\.jpg|\.gif)$/';
		$replacement ="img/\$1__{$w}x{$h}\$2";
		$imageUrl = preg_replace($pattern, $replacement, $imageSrc[0]);
		$html = '<img src="' . $imageUrl . '" alt="' . the_title('', '', false) . '" />';
		return $html;
}

//浓缩图结束

//摘要开始
function custom_excerpt_length($length){return 220;}
function custom_excerpt_more($more){return '&nbsp;......';}
add_filter('excerpt_length', 'custom_excerpt_length');
add_filter('excerpt_more','custom_excerpt_more');
//摘要结束



?>
